package edu.paper.job.service.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import edu.paper.job.dao.ApplicantDao;
import edu.paper.job.domain.Applicant;
import edu.paper.job.service.ApplicantService;

/**
 * 申请者业务逻辑类
 * @author bowen
 *
 */
@Service
public class ApplicantServiceImpl implements ApplicantService{

	@Autowired
	private ApplicantDao applicantDao;
	
	public List<Applicant> find(Applicant applicant) {
		return applicantDao.find(applicant);
	}

	public Applicant get(Serializable id) {
		return applicantDao.get(id);
	}

	public void insert(Applicant applicant) {
		applicantDao.insert(applicant);
	}

	public void update(Applicant applicant) {
		applicantDao.update(applicant);
	}

	public void deleteById(Serializable id) {
		applicantDao.deleteById(id);
	}

	public void delete(Serializable[] ids) {
		applicantDao.delete(ids);
	}


	public boolean register(Applicant applicant) {
		Applicant params = new Applicant();
		params.setUsername(applicant.getUsername());
		if(applicantDao.find(params).size() > 0) {
			//用户名重复，注册失败
			return false;
		}else {
			//否则注册成功
			applicantDao.insert(applicant);
			return true;
		}
			
	}

	public Applicant login(Applicant applicant) {
		List<Applicant> applicants = applicantDao.find(applicant);
		if(applicants.size() > 0) {
			//登陆成功
			return applicants.get(0);
		}else {
			//登陆失败
			return null;
		}
		
	}
	
}
